package com.wanmait.translate.supplier.controller;

import com.wanmait.translate.pojo.SupplierTravel;
import com.wanmait.translate.supplier.service.AllTrackingRequestService;
import com.wanmait.translate.supplier.service.TrackingRequestService;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller

public class TrackingController {
    @Resource
    private TrackingRequestService trackingRequestService;
    @Resource
    private AllTrackingRequestService allTrackingRequestService;
    //历史供应商
    @RequestMapping("/supplier/tracking")
    public void tracking() {
    }
    //提交的表单
    @RequestMapping("/supplier/trackingForm")
    public void trackingForm() {
    }
    //出差申请的表单
    @RequestMapping("/supplier/trackingFormRequest")
    public void trackingFormRequest() {
    }
    //
    @RequestMapping("/supplier/travel")
    public void travel() {
    }
    //出差申请

    @RequestMapping("supplier/trackingRequest")
    public ModelAndView trackingRequest(String name)
    {
        name="张三";
        ModelAndView modelAndView=new ModelAndView();
        List<SupplierTravel> al =allTrackingRequestService.listUserAllSupplierTravel(name);
        System.out.print(al.size());
        modelAndView.addObject("al",al);
        return modelAndView;
    }
    //出差提交

    @PostMapping("supplier/suc")
    public void trackingRequestform(SupplierTravel supplierTravel){

        trackingRequestService.insert(supplierTravel);




       // return ;

    }

    @InitBinder
    public void initBinder(WebDataBinder binder, WebRequest request) {
        //转换日期 注意这里的转化要和传进来的字符串的格式一直 如2015-9-9 就应该为yyyy-MM-dd
        DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
    }
    //供应商跟踪
    @RequestMapping("supplier/follow")
    public void follow(){}
    //出差基本信息
    @RequestMapping("supplier/trip")
    public void trip(){}
}
